package com.google.code.synchronized_player;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;


public class Client implements Runnable{
	
private String ip;
private int port;

public Client(String ip, int port) {
this.ip = ip;
this.port = port;

}
	
public void phoneClient(){

	try {
		String sender = "lol";
		Socket socket = new Socket (ip, port);
//		Socket socket = new Socket ("127.0.0.1", 27960);
		byte[] buffer = new byte[1 + sender.length()];
		buffer[0] = (byte)(sender.length());
		byte[] buff_tmp = sender.getBytes("US-ASCII");
	    for (int i = 0; i < buff_tmp.length; i++)
	    {
	    	buffer[i+1] = buff_tmp[i];
	    }
		OutputStream os = socket.getOutputStream();
		os.write(buffer);
		os.flush();
//		
//		OutputStream sout = socket.getOutputStream();
//		
//		//InputStream sin = socket.getInputStream();
//		PrintWriter output = new PrintWriter(sout);
//		output.println("Hello");
//		output.flush();
		//int number = 105;
		//sout.write(number);
		//socket.close();
//		sout.flush();
		//number = sin.read();
//        System.out.println("The server was very polite. It sent me this : " + number);
//        System.out.println("Looks like the server is pleased with us. Go ahead and enter more lines.");
//        System.out.println();
		socket.close();
	} catch (UnknownHostException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} 	
}

@Override
public void run() {
	// TODO Auto-generated method stub
	phoneClient();
}
}
